package com.inventory.form;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.inventory.persistence.User;

public class UserValidator implements Validator {
	
	@Override
	public boolean supports(Class<?> clazz) {
		return User.class.equals(clazz);
	}
	
	@Override
	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmpty(errors, "name", "errors.user.name.required");
		ValidationUtils.rejectIfEmpty(errors, "userName", "errors.user.id.required");
		ValidationUtils.rejectIfEmpty(errors, "password", "errors.user.password.required");
	}
	
}
